package com.app.controller;

import com.app.aop.has.HasRedissonLock;
import com.app.aop.has.HasRole;
import com.app.domain.bo.SettingBo;
import com.app.framework.common.R;
import com.app.service.SettingService;
import jakarta.annotation.Resource;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 系统设置控制器
 */
@RestController
@RequestMapping("/api/setting")
public class SettingController {

    @Resource
    private SettingService settingService;

    /**
     * 系统设置详情
     */
    @GetMapping("/details")
    public R<Map<String, Object>> details() {
        return R.ok(settingService.details());
    }

    /**
     * 修改系统设置
     */
    @HasRole()
    @HasRedissonLock("update_setting")
    @PostMapping("/update")
    public R<?> updateOne(@RequestBody SettingBo bo) {
        Assert.notNull(bo.getCode(), "配置标识不能为空");
        Assert.notNull(bo.getContent(), "配置内容不能为空");
        settingService.updateOne(bo);
        return R.ok(null, "修改成功");
    }

}